package com.sxu.demo;

import java.time.LocalTime;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * invokeAny
 */
public class Test5 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(2);
        String string = pool.invokeAny(Arrays.asList(
                () -> {
                    System.out.println("1 Begin...");
                    System.out.println(LocalTime.now());
                    Thread.sleep(1000);
                    System.out.println("1 End...");
                    return "1";
                },
                () -> {
                    System.out.println("2 Begin...");
                    System.out.println(LocalTime.now());
                    Thread.sleep(500);
                    System.out.println("2 End...");
                    return "2";
                },
                () -> {
                    System.out.println("3 Begin...");
                    System.out.println(LocalTime.now());
                    Thread.sleep(1500);
                    System.out.println("3 End...");
                    return "3";
                }
        ));
        System.out.println(string);
        System.out.println(LocalTime.now());
    }
}
